import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'
import { formatBytes } from '@/utils'

import api from '@/api'
const { listNamespaces } = api

// 镜像仓库列表
export function getMirroringBasicColumns(): BasicColumn[] {
  return [
    {
      title: '镜像名称',
      dataIndex: 'name'
    },
    {
      title: '仓库类型',
      width: 80,
      dataIndex: 'nameType'
    },
    {
      title: '所属组织',
      dataIndex: 'namespace'
    },
    {
      title: '版本数',
      align: 'right',
      width: 70,
      dataIndex: 'numImages'
    },
    {
      title: '下载次数',
      align: 'right',
      width: 80,
      dataIndex: 'numDownload'
    },
    {
      title: '已用空间',
      align: 'right',
      dataIndex: 'size',
      format: (text) => {
        return formatBytes(text)
      }
    },
    {
      title: '更新时间',
      dataIndex: 'updatedAt'
    }
  ]
}
// 镜像列表
export function getDetailBasicColumns(): BasicColumn[] {
  return [
    {
      title: '镜像版本',
      dataIndex: 'tag'
    },
    {
      title: '下载指令',
      dataIndex: 'path',
      customEllipsis: true,
      width: 540
    },
    {
      title: '镜像大小',
      align: 'right',
      dataIndex: 'size',
      format: (text) => {
        return formatBytes(text)
      }
    },
    {
      title: '更新时间',
      dataIndex: 'updated'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    baseColProps: {
      span: 6,
      md: 10,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: 'name',
        label: '镜像名称',
        component: 'Input'
      },
      {
        field: 'namespace',
        label: '所属组织',
        component: 'ApiSelect',
        componentProps: {
          api: listNamespaces,
          resultField: 'result.list',
          labelField: 'name',
          valueField: 'name',
          immediate: true
        }
      }
    ]
  }
}
